package com.graduation.mathematics.ui.activity;

import android.content.Intent;
import android.util.SparseArray;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.graduation.mathematics.R;
import com.graduation.mathematics.base.BaseActivity;
import com.graduation.mathematics.ui.fragment.teacher.AddStudentFragment;
import com.graduation.mathematics.ui.fragment.teacher.ExercisesManagerFragment;
import com.graduation.mathematics.ui.fragment.teacher.StudySuggestFragment;

/**
 * @ProjectName: mathematicsWorkbook
 * @Package: com.graduation.mathematics.ui.activity
 * @ClassName: TeacherActivity
 * @Description: java类作用描述
 * @Author: APC
 * @CreateDate: 2021/2/23 15:28
 * @Version: 1.0
 */
public class TeacherActivity extends BaseActivity {
    private RadioGroup mTabRadioGroup;
    private SparseArray<Fragment> mFragmentSparseArray;

    @Override
    protected int getLayout() {
        return R.layout.activity_teacher;
    }

    @Override
    protected void initDataAndEvent() {
        initView();

        mFragmentSparseArray = new SparseArray<>();
        mFragmentSparseArray.append(R.id.tab_add_student, AddStudentFragment.newInstance());
        mFragmentSparseArray.append(R.id.tab_exercises_manager, ExercisesManagerFragment.newInstance());
        mFragmentSparseArray.append(R.id.tab_study_suggest, StudySuggestFragment.newInstance());
        mTabRadioGroup.setOnCheckedChangeListener((group, checkedId) -> {
            // 具体的fragment切换逻辑可以根据应用调整，例如使用show()/hide()
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                    mFragmentSparseArray.get(checkedId)).commit();
        });
        // 默认显示第一个
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_container,
                mFragmentSparseArray.get(R.id.tab_add_student)).commit();

    }

    private void initView(){
        mTabRadioGroup = findView(R.id.tabs_rg);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
